<template>
    <view>
        <cu-custom bgColor="bg-gradual-green" :isBack="true">
            <block slot="backText"></block>
            <block slot="content">修改资料</block>
        </cu-custom>

        <form>
            <view class="cu-form-group">
                <view class="title">手机号码</view>
                <input placeholder="输入您的手机号码" name="input" v-model="userinfo.mobile" disabled="false"></input>
                <view class="cu-capsule radius">
                    <button open-type="getPhoneNumber" @getphonenumber="getPhone" size="mini" type="primary">获取微信手机号</button>
                </view>
            </view>

            <view class="cu-form-group align-start">
                <view class="title">个性签名</view>
                <textarea placeholder="输入您的个性签名" v-model="userinfo.bio"></textarea>
            </view>
        </form>

        <view class="padding flex flex-direction">
            <button class="cu-btn bg-blue margin-tb-sm lg" @click="editInfo">保存</button>
        </view>
    </view>
</template>

<script>
    import {
        mapState
    } from 'vuex';
    export default {
        data() {
            return {
                bio:''
            }
        },
        onShow() {
            console.log("success")
        },
        onHide() {
            console.log("hehe")
        },
        onLoad() {
            console.log(this.userinfo,123);
            this.bio = this.userinfo.bio;
        },
        computed: {
            ...mapState({
            	userinfo: state => state.userinfo
            })
        },
        methods: {
            getPhone(res){
                uni.login({
                	provider: 'weixin',
                	success: (loginRes) => {
                        this.$http.post('getMobile',{
                            code:loginRes.code,
                            iv:res.detail.iv,
                            encryptedData:res.detail.encryptedData
                        }).then(res=>{
                            this.userinfo.mobile = res.data;
                            // res.data
                            console.log(res)
                        })
                	}
                });
            },
            editInfo(){
                this.$http.post('editInfo',{
                    bio:this.bio
                }).then(res=>{
                    console.log(res)
                    if(res.code == 1){
                        uni.showToast({
                            title: '保存成功'
                        })
                        
                        setTimeout(()=>{
                            uni.navigateBack({
                                delta:1
                            })
                        },1500)
                    }
                })
            }
        }
    }
</script>

<style lang="less" scoped>

</style>
